#include <iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int arr[1000] = { 0 }, f = 0;
void quicksort(int left, int right) {
    int h, q, w, temp;
    if (left > right)
        return;
    temp = arr[left];
    h = left;
    q = right;
    while (h != q)
    {
        while (arr[q] >= temp && h < q)
            q--;
        while (arr[h] <= temp && h < q)
            h++;

        if (h < q)
        {
            w = arr[h];
            arr[h] = arr[q];
            arr[q] = w;
        }

    }
    arr[left] = arr[h];
    arr[h] = temp;
    quicksort(left, h - 1);
    quicksort(h + 1, right);

}
int main() {
    int a[100][100] = { 0 };
    int c = 0, b = 0;
    cin >> c >> b;
    int i = 0, g = 0;
    for (i = 0; i < c; i++)
    {
        for (g = 0; g < b; g++)
        {
            cin >> a[i][g];
        }

    }
    for (i = 0; i < c; i++)
    {
        for (g = 0; g < b; g++)
        {
            arr[f] = a[c][b];
            f++;
        }
    }int n = c * b, v = 0, x = 0;
    quicksort(1, n);
    for (v = 1; v <= n - 2; v++)
    {
        x += arr[v];

    }
    cout << x / (n - 2);
}




}